package com.woniuxy.yoga.business.web.controller;


import com.woniuxy.yoga.business.model.dto.storecount.StaticDataDto;
import com.woniuxy.yoga.business.model.form.storecount.StoreCountSelForm;
import com.woniuxy.yoga.business.service.StoreCountService;
import com.woniuxy.yoga.commons.core.model.PageInfo;
import com.woniuxy.yoga.commons.core.model.Result;
import com.xxl.job.core.handler.annotation.XxlJob;
import io.swagger.annotations.Api;
import com.woniuxy.yoga.commons.core.util.JWTUtil;
import com.woniuxy.yoga.commons.web.log.YogaLog;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * <p>
 * 商家统计表 前端控制器
 * </p>
 *
 * @author 韦用文,刘存益,郎腾霄
 * @since 2023年11月28日
 */
@RestController
@RequestMapping("/storeCount")
@Api(tags = "门店统计相关接口")
public class StoreCountController {
    @Autowired
    private StoreCountService storeCountService;
    @Autowired
    private XxlJobTask xxlJobTask;
    /**
     *根据条件分页查询商店统计表
     * @param form
     * @return
     */
    @PostMapping("/selStoreCount.bu")
    @ApiOperation("根据查询商店统计表")
    public Result<PageInfo> selStoreCount(@RequestBody StoreCountSelForm form){
        PageInfo pageInfo = storeCountService.selStoreStatis(form);
        return Result.getResult(PageInfo.class).setMessage("查询成功").setData(pageInfo);
    }

    /**
     * 添加定时任务
     * @return
     */
    @GetMapping("/addTackTow.bu")
    @ApiOperation("添加门店统计定时任务")
    public Result<String> addTackTow(){
        xxlJobTask.addTackTow();
        return Result.getResult(String.class).setMessage("添加统计定时任务成功");
    }


    /**
     * 查询统计图数据
     * @return 统计数据
     */
    @GetMapping("/monthStaticData.bu")
    @ApiOperation("查询统计图数据")
    @YogaLog("查询统计图数据")
    public Result<StaticDataDto> monthStaticData(@RequestHeader String authen_token){
        Integer accountId = JWTUtil.getBusinessId(authen_token);
        StaticDataDto staticDataDto = storeCountService.monthStaticData(accountId);
        return Result.getResult(StaticDataDto.class).setMessage("查询成功").setData(staticDataDto);
    }
}

